/*
 * Copyright (c) 2021 Futurewei Technologies, Inc.
 *
 * clang2mpl is licensed under Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan
 * PSL v2. You may obtain a copy of Mulan PSL v2 at:
 *
 *     http://license.coscl.org.cn/MulanPSL2
 *
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY
 * KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
 * NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. See the
 * Mulan PSL v2 for more details.
 */
// RUN: %clang2mpl --ascii --verify %s -- --target=aarch64-linux-elf
// RUN: cat %m | %FileCheck %s

int foo(int a) {
  // CHECK: LOC 2 [[# @LINE + 7 ]]{{$}}
  // CHECK-NEXT: dassign %_switch.[[#SWITCH1:]] 0 (dread i32 %a)
  // CHECK-NEXT: switch (dread i32 %_switch.[[#SWITCH1]]) @L_DEFAULT[[#DEF0:]] {
  // CHECK-NEXT:   0: goto @L_CASE[[#CASE0:]]
  // CHECK-NEXT:   1: goto @L_CASE[[#CASE1:]]
  // CHECK-NEXT:   2: goto @L_CASE[[#CASE2:]]
  // CHECK-NEXT:   3: goto @L_CASE[[#CASE3:]] }
  switch(a) {
    // CHECK: LOC 2 [[# @LINE + 2 ]]{{$}}
    // CHECK-NEXT: @L_CASE[[#CASE0]]
    case 0:
      // CHECK-SAME: LOC 2 [[# @LINE + 2 ]]{{$}}
      // CHECK-NEXT: goto @L_BREAK[[#BREAK0:]]
      break;
    // CHECK: LOC 2 [[# @LINE + 2 ]]{{$}}
    // CHECK-NEXT: @L_CASE[[#CASE1]]
    case 1:
      // CHECK-SAME: LOC 2 [[# @LINE + 2 ]]{{$}}
      // CHECK-NEXT: return (constval i32 4)
      return 4;
    // CHECK: LOC 2 [[# @LINE + 2 ]]{{$}}
    // CHECK-NEXT: @L_CASE[[#CASE2]]
    case 1+1:
    // CHECK: LOC 2 [[# @LINE + 2 ]]{{$}}
    // CHECK-NEXT: @L_CASE[[#CASE3]]
    case 3:
      // CHECK-SAME: LOC 2 [[# @LINE + 2 ]]{{$}}
      // CHECK-NEXT: return (constval i32 11)
      return 11;
    // CHECK: LOC 2 [[# @LINE + 2 ]]{{$}}
    // CHECK-NEXT: @L_DEFAULT[[#DEF0]]
    default:
      // CHECK-SAME: LOC 2 [[# @LINE + 2 ]]{{$}}
      // CHECK-NEXT: return (constval i32 0)
      return 0;
    // CHECK: LOC 2 [[# @LINE + 2 ]]{{$}}
    // CHECK-NEXT: @L_BREAK[[#BREAK0]]
  }

  // CHECK: LOC 2 [[#SWITCH1: @LINE + 4 ]]{{$}}
  // CHECK-NEXT: dassign %_switch.[[#SWITCH2:]] 0 (dread i32 %a)
  // CHECK-NEXT: switch (dread i32 %_switch.[[#SWITCH2]]) @L_DEFAULT[[#DEF1:]] {
  // CHECK-NEXT:   0: goto @L_CASE[[#CASE00:]] }
  switch(a) {
    case 0:
      // CHECK: LOC 2 [[# @LINE + 2 ]]{{$}}
      // CHECK-NEXT: goto @L_BREAK[[#BREAK1:]]
      break;
    // CHECK: LOC 2 [[#SWITCH1]]{{$}}
    // CHECK-NEXT: @L_DEFAULT[[#DEF1]] LOC 2 [[# @LINE + 2 ]]{{$}}
    // CHECK-NEXT: @L_BREAK[[#BREAK1]]
  }
  return 2;
}
